package com.css.fxfzypg.modules.saresults.controller;

import cn.hutool.core.io.FileUtil;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.saresults.entity.DzqhGroundMotionParametersEntity;
import com.css.fxfzypg.modules.saresults.param.MotionParametersParam;
import com.css.fxfzypg.modules.saresults.service.GroundMotionParametersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 地震动参数管理
 */
@RestController
@RequestMapping("groundMotionParameters")
public class GroundMotionParametersController {

    @Autowired
    private GroundMotionParametersService groundMotionParametersService;


    /**
     * 导入
     *
     * @return
     */
    @PostMapping("importData")
    public RestResponse importData(@RequestParam MultipartFile file) {
        if (!FileUtil.getSuffix(file.getOriginalFilename()).equals("xls") && !FileUtil.getSuffix(file.getOriginalFilename()).equals("xlsx")) {
            return RestResponse.fail("文件格式不支持!");
        }
        return groundMotionParametersService.importData(file);
    }

    /**
     * 分页查
     *
     * @return
     */
    @GetMapping("queryMotionParameters")
    public RestResponse queryMotionParameters(MotionParametersParam motionParametersParam, HttpServletRequest request,String geom) {
        return groundMotionParametersService.queryMotionParameters(motionParametersParam, request,geom);
    }

    /**
     * 根据id查询
     *
     * @return
     */
    @GetMapping("getGmpById")
    public RestResponse getGmpById(String gmpId) {
        return groundMotionParametersService.getGmpById(gmpId);
    }

    /**
     * 撤设或新设
     *
     * @return
     */
    @PostMapping("demolitionOrSave")
    public RestResponse demolitionOrSave(@RequestBody DzqhGroundMotionParametersEntity entity) {
        return groundMotionParametersService.demolitionOrSave(entity);
    }

    /**
     * 恢复
     */
    @GetMapping("restoreData")
    public RestResponse restoreData(String reasonForChange, String approvalDocuments, String originalId, String gmpId,String type) {
        return groundMotionParametersService.restoreData(reasonForChange, approvalDocuments, originalId, gmpId,type);
    }

    /**
     * 导出数据
     */
    @GetMapping("exportData")
    public void exportData(MotionParametersParam param, HttpServletResponse response) {
        groundMotionParametersService.exportData(param,response);
    }

    /**
     * 删除数据
     */
    @GetMapping("deleteData")
    public RestResponse deleteData(String ids) {
        return groundMotionParametersService.deleteData(ids);
    }

    /**
     * 根据省市县查街道和乡镇个数
     */
    @GetMapping("getNumberByRegion")
    public RestResponse getNumberByRegion(String province,String city,String county) {
        return groundMotionParametersService.getNumberByRegion(province,city,county);
    }

    @GetMapping("getByGeom")
    public RestResponse getByGeom(MotionParametersParam motionParametersParam,String geom){
        return groundMotionParametersService.getByGeom(motionParametersParam,geom);
    }



}
